// JavaScript Document
$.validator.addMethod("creditCard", function(value, element) {  
return this.optional(element) ||  /^[0-9]{16,}$/i.test(value);  
}, "<strong>CREDIT CARD</strong> requires 16 Digits");	
$.validator.addMethod("cvv", function(value, element) {  
return this.optional(element) ||  /^[0-9]{3,4}$/i.test(value);  
}, "<strong>CVV</strong>  Minimum of 3 Digits");
$.validator.addMethod("cvv2", function(value, element) {  
return this.optional(element) ||  /^[0-9]{4,}$/i.test(value);  
}, "<strong>CVV</strong> Requires 4 Digits");
$.validator.addMethod("fullname", function(value, element) {  
return this.optional(element) ||  /^[a-zA-Z]{2,}[ a-zA-Z]{1,}?$/i.test(value);  
	}, "The <strong>FIRSTNAME</strong> is invalid");
/*$.validator.addMethod("fullname2", function(value, element) {  
return this.optional(element) ||  /^[a-zA-Z]{1,}?[ ][a-zA-Z]{1,}?$/i.test(value);  
	}, "Please enter your <strong>LASTNAME</strong>");	*/
$.validator.addMethod("phone", function(value, element) {  
	return this.optional(element) ||  /^[0-9]{10,11}$/i.test(value);  
	}, "Phone Requires 10 Digits");
$.validator.addMethod("phone2", function (value, element) {
    return this.optional(element) || /^[(][0-9]{3,}[)][ ][0-9]{3,}[-][0-9]{4,}$/i.test(value);
}, "Phone Requires 10 Digits");
$.validator.addMethod("zipcode", function (value, element) {  
	return this.optional(element) ||  /^[0-9]{5,}$/i.test(value);  
	}, "<strong>ZIP</strong> requires 5 digits");	
$.validator.addMethod("phoneAU", function(value, element) {  
	return this.optional(element) ||  /^[(][0-9]{2,}[)][ ][0-9]{4,}[-][0-9]{4,}$/i.test(value);  
	}, "Please enter a valid phone");
	$.validator.addMethod("phoneGeneric", function(value, element) {  
	return this.optional(element) ||  /^[0-9-]{6,16}$/i.test(value);  
	}, "Please enter a valid phone");

if ($('#emailOnly').length) {
$('#checkoutForm2 p:eq(0), #checkoutForm2 p:eq(1)').remove()
}

if ($('.validateThisForm').length) {
$("#checkoutForm2.validateThisForm").validate({
	rules: {
	first_name: "required",
	fullName: "required",
	email: "required email",
	dayPhoneIndex: {
			required: true
		}
	},
	errorElement: "em",
		errorPlacement: function(error, element) {
		error.appendTo(element.parent());
	},
	messages: {
	first_name: {required: "<strong>Your FIRST NAME</strong> is required"},
	fullName: {required: "<strong>Your FIRST NAME</strong> is required"},
	email: {required: "<strong>A VALID EMAIL ADDRES</strong> is required", email: "Please enter a <strong>VALID EMAIL ADDRESS</strong>"},
	dayPhoneIndex: {required: "<strong>A VALID DAYTIME PHONE NUMBER</strong> is required",phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},	
	zip: {required: "<strong>A 5 DIGIT ZIP CODE</strong> is required", remotezip:"The <strong>ZIP CODE</strong> entered is invalid"}	
	},
	submitHandler: function(form) {
		if ($('#ajaxLoader').length) {
			$('#ajaxLoader').overlay({ mask: { color: '#000', loadSpeed: 0, opacity: 0.85 }, closeOnClick: false, oneInstance: false, top: 'center', onLoad: function() {
					setInterval("showAjax()",500)
				}
			});
			$('#ajaxLoader').overlay().load();
			$('#ajaxLoader').addClass('animated flipInX');
			internalLink = true;
			setTimeout(function () {
				form.submit();
			}, 2000);
		} else {
			form.submit();
		}
   	}
});

} else {
if ($('body.isIndex').length === 0) {
$("#checkoutForm2").validate({
	groups: {
    ExpDate: "fields_expmonth fields_expyear"
  },
	rules: {
	fullName: "required",
	lastName: "required",
	email: "required email",
	zip: {

  },
  dayPhone: "required",
	cc_number: "required creditCard",
	fields_expmonth: "required",
	fields_expyear: "required",
	cc_cvv: "required cvv",
    country: "required",
    state: "required",
    city: {
		required: true,
		minlength: 2
		},
    address: {
		required: true,
		minlength: 2
		}
	},	
	errorElement: "em",
		errorPlacement: function(error, element) {
		error.appendTo(element.parent());
	},
	messages: {
	fullName: {required: "<strong>Your FIRST NAME</strong> is required"},
	lastName: {required: "<strong>Your LAST NAME</strong> is required"},
	email: {required: "<strong>A VALID EMAIL ADDRESS</strong> is required", email: "Please enter a <strong>VALID EMAIL ADDRESS</strong>"},
	emailIndex: {required: "<strong>EMAIL ADDRESS</strong> is required", email: "Please enter a <strong>VALID EMAIL</strong>"},	
	dayPhone: {required: "<strong>A VALID DAYTIME PHONE NUMBER</strong> is required", phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},		
	dayPhoneIndex: {required: "<strong>A PHONE NUMBER</strong> is required", phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},			
	zip: {required: "<strong>A 5 DIGIT ZIP CODE</strong> is required", remotezip:"The <strong>ZIP CODE</strong> entered is invalid"},	
	cc_number: {required: "<strong>CARD NUMBER</strong> is required", creditCard: "<strong>CREDIT CARD</strong> requires 16 Digits"},
	fields_expmonth: { required: "<strong>EXPIRATION MONTH</strong> is required"},
	fields_expyear: { required: "<strong>EXPIRATION YEAR</strong> is required"},
	cc_cvv: {required: "<strong>CVV</strong> is required"},
	country: {required: "<strong>COUNTRY</strong> is required"},
	state: { required: "<strong>STATE</strong> is required"},
	address: { required: "<strong>ADDRESS</strong> is required", minlength: "Enter a valid <strong>ADDRESS</strong>"},
	city: { required: "<strong>CITY</strong> is required", minlength: "Enter a valid <strong>CITY</strong>"}
	},
	submitHandler: function(form) {
/* added if statement in case there is no ajax loader */
			if ($('#ajaxLoader').length) {
				$('#ajaxLoader').overlay({ mask: { color: '#000', loadSpeed: 0, opacity: 0.85 }, closeOnClick: false, oneInstance: false, top: '30%', onLoad: function() {
	      internalLink = true;
				form.submit(); 
				setInterval("showAjax()",500) }});
	      $('#ajaxLoader').overlay().load();
				$('#ajaxLoader').addClass('animated flipInX');
			} else {
				form.submit();
			}
   	}
});
} 
}

if ($('#checkoutForm2').length) {
var $alt_phone = $("input[name=alt_phone]", "#checkoutForm2");
var $dayPhoneIndex = $("input[name=dayPhoneIndex]", "#checkoutForm2");
var $dayPhone = $("input[name=dayPhone]", "#checkoutForm2");
var $zip = $("input[name=zip]", "#checkoutForm2");
var $cc_number = $("input[name=cc_number]", "#checkoutForm2");
var $cc_cvv = $("input[name=cc_cvv]", "#checkoutForm2");

$alt_phone.validate();
$dayPhone.validate();
$dayPhoneIndex.validate();
$zip.validate();
$cc_number.validate();
$cc_cvv.validate();

// $alt_phone.mask2("?(999) 999-9999");
// $dayPhone.mask2("?(999) 999-9999");
// // $dayPhoneIndex.mask2("?(999) 999-9999");
// $zip.mask2("?99999");
// $cc_number.mask2("?9999999999999999");
// $cc_cvv.mask2("?999");

}



/* toolTip */
$('input[name=cc_cvv], input[name=cc_cvv]').hover(function (e) {
   $('#tooltip').show();
  }, 
  function () {
   $('#tooltip').hide();
  }
);
$('#cvv2pop').hover(
  function () {
    $('#tooltip').show();
  }, 
  function () {
   $('#tooltip').hide();
  }
);



/* index validation */
$("#checkoutForm").validate({
	groups: {
    ExpDate: "fields_expmonth fields_expyear"
  },
	rules: {
	fullName: "required",
	lastName: "required",
	email: "required email",
	emailIndex: "required email",	
	address: {
		required: true,
		minlength: 2
	},
	city: {
		required: true,
		minlength: 2
	},
	dayPhone: {
			required: true

		},
	dayPhoneIndex: {
			required: true
		}		
		,zip: {

    },
    alt_phone: {required: false, phone2: false},
	cc_number: "required creditCard",
	fields_expmonth: "required",
	fields_expyear: "required",
	cc_cvv: "required cvv",
    country: "required"
	},	
	errorElement: "em",
		errorPlacement: function(error, element) {
		error.appendTo(element.parent());
	},
	messages: {
	fullName: {required: "<strong>Your FIRST NAME</strong> is required"},
	lastName: {required: "<strong>Your LAST NAME</strong> is required"},
	email: {required: "<strong>A VALID EMAIL ADDRESS</strong> is required", email: "Please enter a <strong>VALID EMAIL ADDRESS</strong>"},
	emailIndex: {required: "<strong>EMAIL ADDRESS</strong> is required", email: "Please enter a <strong>VALID EMAIL</strong>"},	
	dayPhone: {required: "<strong>A VALID DAYTIME PHONE NUMBER</strong> is required", phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},		
	dayPhoneIndex: {required: "<strong>A PHONE NUMBER</strong> is required", phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},			
	zip: {required: "<strong>A 5 DIGIT ZIP CODE</strong> is required", remotezip:"The <strong>ZIP CODE</strong> entered is invalid"},	
	cc_number: {required: "<strong>CARD NUMBER</strong> is required", creditCard: "<strong>CREDIT CARD</strong> requires 16 Digits"},
	fields_expmonth: { required: "<strong>EXPIRATION MONTH</strong> is required"},
	fields_expyear: { required: "<strong>EXPIRATION YEAR</strong> is required"},
	cc_cvv: {required: "<strong>CVV</strong> is required"},
	country: {required: "<strong>COUNTRY</strong> is required"},
	address: { required: "<strong>ADDRESS</strong> is required", minlength: "Enter a valid <strong>ADDRESS</strong>"},
	city: { required: "<strong>CITY</strong> is required", minlength: "Enter a valid <strong>CITY</strong>"}
	},
	submitHandler: function(form) {
			form.submit();
			//$('#ajaxLoader').overlay({ mask: { color: '#000', loadSpeed: 0, opacity: 0.85 }, closeOnClick: false, oneInstance: false, top: '30%', onLoad: function() {
			//form.submit(); 
			/*setInterval("showAjax()",500) }});*/
     // $('#ajaxLoader').overlay().load();
            internalLink = true
   	}
});

if ($('#checkoutForm').length) {
var $alt_phone = $("input[name=alt_phone]", "#checkoutForm");
var $dayPhoneIndex = $("input[name=dayPhoneIndex]", "#checkoutForm");
var $dayPhone = $("input[name=dayPhone]", "#checkoutForm");
var $zip = $("input[name=zip]", "#checkoutForm");
var $cc_number = $("input[name=cc_number]", "#checkoutForm");
var $cc_cvv = $("input[name=cc_cvv]", "#checkoutForm");

$alt_phone.validate();
$dayPhone.validate();
$dayPhoneIndex.validate();
$zip.validate();
$cc_number.validate();
$cc_cvv.validate();

$alt_phone.mask2("?(999) 999-9999");
$dayPhone.mask2("?(999) 999-9999");
$dayPhoneIndex.mask2("?(999) 999-9999");
$zip.mask2("?99999");
$cc_number.mask2("?9999999999999999");
$cc_cvv.mask2("?999");
}



$("#checkoutForm3").validate({
	groups: {
    ExpDate: "fields_expmonth fields_expyear"
  },
	rules: {
	fullName: "required",
	lastName: "required",
	email: "required email",
	zip: {

  },
  dayPhone: "required",
	cc_number: "required creditCard",
	fields_expmonth: "required",
	fields_expyear: "required",
	cc_cvv: "required cvv",
    country: "required",
    state: "required",
    city: {
		required: true,
		minlength: 2
		},
    address: {
		required: true,
		minlength: 2
		}
	},	
	errorElement: "em",
		errorPlacement: function(error, element) {
		error.appendTo(element.parent());
	},
	messages: {
	fullName: {required: "<strong>Your FIRST NAME</strong> is required"},
	lastName: {required: "<strong>Your LAST NAME</strong> is required"},
	email: {required: "<strong>A VALID EMAIL ADDRESS</strong> is required", email: "Please enter a <strong>VALID EMAIL ADDRESS</strong>"},
	emailIndex: {required: "<strong>EMAIL ADDRESS</strong> is required", email: "Please enter a <strong>VALID EMAIL</strong>"},	
	dayPhone: {required: "<strong>A VALID DAYTIME PHONE NUMBER</strong> is required", phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},		
	dayPhoneIndex: {required: "<strong>A PHONE NUMBER</strong> is required", phone: "Phone requires <strong>10 digits</strong>", remote:"Please verify if your phone number is correct."},			
	zip: {required: "<strong>A 5 DIGIT ZIP CODE</strong> is required", remotezip:"The <strong>ZIP CODE</strong> entered is invalid"},	
	cc_number: {required: "<strong>CARD NUMBER</strong> is required", creditCard: "<strong>CREDIT CARD</strong> requires 16 Digits"},
	fields_expmonth: { required: "<strong>EXPIRATION MONTH</strong> is required"},
	fields_expyear: { required: "<strong>EXPIRATION YEAR</strong> is required"},
	cc_cvv: {required: "<strong>CVV</strong> is required"},
	country: {required: "<strong>COUNTRY</strong> is required"},
	state: { required: "<strong>STATE</strong> is required"},
	address: { required: "<strong>ADDRESS</strong> is required", minlength: "Enter a valid <strong>ADDRESS</strong>"},
	city: { required: "<strong>CITY</strong> is required", minlength: "Enter a valid <strong>CITY</strong>"}
	},
	submitHandler: function(form) {
		  $('#modalForA').remove();
/* added if statement in case there is no ajax loader */
			if ($('#ajaxLoader').length) {
				$('#ajaxLoader').overlay({ mask: { color: '#000', loadSpeed: 0, opacity: 0.85 }, closeOnClick: false, oneInstance: false, top: '30%', onLoad: function() {
	      internalLink = true;
				form.submit(); 
				setInterval("showAjax()",500) }});
	      $('#ajaxLoader').overlay().load();
				$('#ajaxLoader').addClass('animated flipInX');
				$('#ajaxLoader').css('zIndex', 9999);
			} else {
				form.submit();
			}
   	}
});

